#!/usr/bin/env rc

fn has_color {
  ! ~ $#$1 0 && ! ~ $#(BOLD_$1) 0
}

fn has_colors {
  for (color) {
    if (! has_color $color) {
      return 1
    }
  }

  return 0
}

if (has_colors BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE) {
  if (~ $#BACKGROUND 0) {
    BACKGROUND=$BLACK
  }

  if (~ $#FOREGROUND 0) {
    FOREGROUND=$WHITE
  }

  if (~ $#CURSOR_COLOR 0) {
    CURSOR_COLOR=$BLUE
  }

  echo '*foreground:  #'^$FOREGROUND
  echo '*background:  #'^$BACKGROUND
  echo '*cursorColor: #'^$CURSOR_COLOR
  echo '*color0:      #'^$BLACK
  echo '*color8:      #'^$BOLD_BLACK
  echo '*color1:      #'^$RED
  echo '*color9:      #'^$BOLD_RED
  echo '*color2:      #'^$GREEN
  echo '*color10:     #'^$BOLD_GREEN
  echo '*color3:      #'^$YELLOW
  echo '*color11:     #'^$BOLD_YELLOW
  echo '*color4:      #'^$BLUE
  echo '*color12:     #'^$BOLD_BLUE
  echo '*color5:      #'^$MAGENTA
  echo '*color13:     #'^$BOLD_MAGENTA
  echo '*color6:      #'^$CYAN
  echo '*color14:     #'^$BOLD_CYAN
  echo '*color7:      #'^$WHITE
  echo '*color15:     #'^$BOLD_WHITE
}